#!/usr/bin/env python
# -*- coding: utf-8 -*-
import json
import socket

from dronekit import connect

# 接受GPS信息目标电脑的IP地址和端口
UDP_IP_ADDRESS = "10.42.0.240"  # 本机
UDP_PORT_NO = 1111
# 创建一个socket
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
vehicle = connect('/dev/ttyUSB0', wait_ready=True, baud=921600)
info_str = None

global_position = []

while True:
    position = {
        '经度': vehicle.location.global_frame.lat,
        '纬度': vehicle.location.global_frame.lon
    }
    global_position.append(position)
    client.sendto((json.dumps(position)).encode('utf-8'), (UDP_IP_ADDRESS, UDP_PORT_NO))
